home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / cprog / tdddconv.lha / tddd2off.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-12  |  1.2 KB  |  53 lines

  1. /* tddd2off.c - convert TDDD (or TTDDD) file to OFF file
  2.  *            - written by Glenn M. Lewis - 10/29/91
  3.  */
  4.  
  5. static char rcs_id[] = "$Id: tddd2off.c,v 1.2 1991/11/08 00:30:31 glewis Exp glewis $";
  6.  
  7. #include <stdio.h>
  8. #include "ttdddlib.h"
  9.  
  10. main(argc, argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     char filename[256], rootname[256], *c1, *c2;
  15.     int i;
  16.     WORLD *world;
  17.     FILE *inp;
  18.     int split = 0, geom_only = 0;
  19.  
  20.     filename[0] = '\0';
  21.     strcpy(rootname, "model");    /* The default for reading stdin */
  22.     for (i=1; i<argc; i++) {
  23.         if (argv[i][0] == '-') {
  24.             switch(argv[i][1]) {
  25.                 case 's':    split = 1; break;
  26.                 case 'g':    geom_only = 1; break;
  27.                 case 'h':
  28.                 default:
  29.         fprintf(stderr, "Usage: %s [-geom_only] [-split] [infile] [outfile]\n",
  30.                 argv[0]);
  31.                 exit(-1);
  32.             }
  33.         } else if (filename[0]) {
  34.             strcpy(rootname, argv[i]);
  35.         } else {
  36.             strcpy(filename, argv[i]);    /* Make root of filename the default */
  37.             for (c1=rootname,c2=argv[i]; (*c1 = *c2++) && *c1!='.'; c1++) ;
  38.             *c1 = '\0';
  39.         }
  40.     }
  41.  
  42.     if (!filename[0]) inp = stdin;
  43.     else if (!(inp = fopen(filename, "r"))) {
  44.         fprintf(stderr, "Can't open '%s' for input.\n", filename);
  45.         exit(-1);
  46.     }
  47.  
  48.     world = read_World(inp);
  49.     write_OFF(world, rootname, split, geom_only);
  50.     exit(0);
  51. }
  52.  
  53.